package vn.intelsoft.vlogvn;


import java.util.List;

import vn.intelsoft.vlogvn.adapter.MenuAdapter;
import vn.intelsoft.vlogvn.instance.Vlogger;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

@SuppressLint("ValidFragment")
public class SlideMenuFragment extends ListFragment implements OnItemClickListener {
	private List<Vlogger> mVloggers;
	
	public SlideMenuFragment(List<Vlogger> vloggers) {
		this.mVloggers = vloggers;
	}
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.list, null);
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		if(mVloggers != null){
			MenuAdapter adapter = new MenuAdapter(getActivity(), mVloggers);
			setListAdapter(adapter);
			getListView().setOnItemClickListener(this);
		}
	}
	@Override
	public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
		Vlogger vlogger = mVloggers.get(position);
		
		Intent it = new Intent(getActivity(), VlogActivity.class);
		it.putExtra("name", vlogger.name);
		it.putExtra("username", vlogger.username);
		((BaseActivity)getActivity()).getSlidingMenu().toggle();
		startActivity(it);
		if (getActivity() instanceof VlogActivity){
			getActivity().finish();
		}
	}

}
